import wx
from operator import itemgetter

import pyciv.rules

class ScorePanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs) 
        
        self.text = wx.StaticText(self, wx.ID_ANY, "")

    def update(self, engine):
        string = "Score/Workers/Hexes\n"
        result = []
        for player in engine.state.players:
            if not player.is_default_player():
                (hexes, other_hexes, workers, other_workers) = player.count_status(engine)
                result.append((workers * pyciv.rules.WORKER_SCORE + hexes, workers, 
                                             hexes, str(player.name)))
        
        result.sort(key=itemgetter(0,1,2), reverse=True)
        for item in result:
            string += "%d/%d/%d %s\n" % item
        self.text.SetLabel(string)
